﻿/**  版本信息模板在安装目录下，可自行修改。
* ShoppingInfo.cs
*
* 功 能： N/A
* 类 名： ShoppingInfo
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2016/8/30 22:03:44   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace Maticsoft.DAL
{
	/// <summary>
	/// 数据访问类:ShoppingInfo
	/// </summary>
	public partial class ShoppingInfo
	{
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetListView(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * ");
            strSql.Append(" FROM v_ShoppingInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Maticsoft.Model.ShoppingInfo GetModel(int userId,int productId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 Id,UserId,ProductId,ProductNum,ProductDesc,CreateTime,IsActive from ShoppingInfo ");
            strSql.Append(" where UserId=@UserId and ProductId=@ProductId and IsActive=1");
            SqlParameter[] parameters = {
					new SqlParameter("@UserId", SqlDbType.Int,4),
                    new SqlParameter("@ProductId", SqlDbType.Int,4)
			};
            parameters[0].Value = userId;
            parameters[1].Value = productId;

            Maticsoft.Model.ShoppingInfo model = new Maticsoft.Model.ShoppingInfo();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 获取购物车厂家列表
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public DataSet GetShoppingCarFactoryNo(int userId)
        {
            string strSql = "select distinct factoryNo from v_ShoppingInfo where userId=@UserId and IsActive=1";
            SqlParameter[] para ={
                                new SqlParameter("@UserId",SqlDbType.Int)
                                };
            para[0].Value = userId;

            return DbHelperSQL.Query(strSql, para);
        }
	}
}

